<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
        #myProgress {
            width: 100%;
            background-color: #ddd;
        }
        
        #myBar {
            width: 1%;
            height: 30px;
            background-color: #4caf81;
        }
    </style>
</head>

<body>
    <h1>JavaScript 进度条</h1>

    <div id="myProgress">
        <div id="myBar"></div>
    </div>

    <br />
    <button onclick="move()">加载</button>
</body>
<script>
    function move() {
        var elem = document.getElementById("myBar");
        var width = 1;
        var timer = setInterval(() => {
            if (width >= 100) {
                clearInterval(timer);
            } else {
                width++;
                elem.style.width = width + "%";
            }
        }, 10);
    }
</script>

</html>